package cn.com.code.hwjs;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author zhengpei
 * @date 2022/5/1
 */
public class hwjs48 {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String[] strs = scanner.nextLine().split(" ");
    int head = Integer.parseInt(strs[1].trim());
    int delete = Integer.parseInt(strs[strs.length - 1].trim());

    List<Integer> arr = new ArrayList<>();
    arr.add(head);
    for (int i = 2; i < strs.length -1 ; i += 2) {
      int l = Integer.parseInt(strs[i].trim());
      int r = Integer.parseInt(strs[i + 1].trim());
      int index = arr.indexOf(Integer.valueOf(r));
      arr.add(index + 1, l);
    }
    arr.remove(Integer.valueOf(delete));
    for (int num : arr) {
      System.out.print(num + " ");
    }


  }

}
